import React, {Component} from 'react'
import {connect} from 'react-redux'
import {actions} from '../../reducers/ducks'

class Ducks extends Component {
    constructor(props) {
        super(props)
    }

    componentWillReceiveProps(nextProps) {
        console.log(nextProps,'receive')
    }

    componentDidMount() {
        this.props.getDucks(101010100)
        .then(res => {
            console.log(res,555)
        })
    }

    render() {
        let {result} = this.props.ducks
        return (
            <div className='ducks-wrapper'>
                <div>
                    {result ? result.city: null}
                </div>
            </div>
        )
    }
}

const mapStateToProps = (state) => {
    return {
        ducks: state.ducks
    }
}

const mapDispatchToProps = (dispatch) => {
    return {
        getDucks: (cityId) => {
            return Promise.resolve(dispatch(actions.getDucks(cityId)))
        }
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(Ducks)